﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 挂载在相机上
/// </summary>
public class SelfRotate : MonoBehaviour {

    /// <summary>
    /// 水平旋转速度
    /// </summary>
    public float speed = 1;
    /// <summary>
    /// 越大，头抬得越高
    /// </summary>
    public float max = 60;
    /// <summary>
    /// //越小，头抬得越低
    /// </summary>
    public float min = -60;

    /// <summary>
    /// //水平旋转结果
    /// </summary>
    private float y;
    /// <summary>
    /// //垂直旋转结果
    /// </summary>
    private float x;

    private void Start()
    {
        //初始位置
        transform.position = Vector3.zero;
        transform.eulerAngles = Vector3.zero;
    }

    void LateUpdate()
    {
        //-----------------------------兼容触屏--------------------------
        if (VIPInput.Press(0))
        {
            //控制旋转
            y += Input.GetAxis("Mouse X") * speed;
            x += Input.GetAxis("Mouse Y") * speed;
            //限制垂直旋转角度
            x = Mathf.Clamp(x, min, max);
            transform.localEulerAngles = new Vector3(-x, y, 0f);
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }

}
